﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace BtLibs
{
    public class FormLib
    {
        public delegate void Run();
        private static bool running = false;
        private static object lockObject = new object();
        public static void AysnRun(Run run)
        {
            lock (lockObject) { if (running) { Log("running..."); return; } else running = true; }
            new Thread(new ThreadStart(delegate
            {
                Log("begin");
                DateTime begin = DateTime.Now;
                try
                {
                    run();
                }
                catch (Exception ex) { Log(ex.ToString()); }
                finally
                {

                    Log("end. time=" + DateTime.Now.Subtract(begin).TotalSeconds + "s");
                    running = false;
                }
            })).Start();
        }
        private static void Log(string msg, Exception ex = null)
        {
            DefaultLogger.Instance.Log(msg, ex);
        }
    }
}
